package cn.org.timespace.plat.service.mc.impl;

import java.util.Date;
import java.util.List;

import cn.org.timespace.ons.util.pager.Pager;
import cn.org.timespace.plat.action.mc.PlatMcInfoModel;
import cn.org.timespace.plat.dao.mc.PlatMcInfoDao;
import cn.org.timespace.plat.service.mc.PlatMcInfoService;
import cn.org.timespace.plat.vo.mc.PlatMcInfo;

public class PlatMcInfoServiceImpl implements PlatMcInfoService {
	private PlatMcInfoDao platMcInfoDao;
	
	public PlatMcInfoDao getPlatMcInfoDao() {
		return platMcInfoDao;
	}

	public void setPlatMcInfoDao(PlatMcInfoDao platMcInfoDao) {
		this.platMcInfoDao = platMcInfoDao;
	}

	@Override
	public void delete(PlatMcInfo instance) {
		// TODO Auto-generated method stub
		platMcInfoDao.delete(instance);
	}

	@Override
	public List<PlatMcInfo> findByCondition(PlatMcInfoModel model) {
		// TODO Auto-generated method stub
		return platMcInfoDao.findByCondition(model);
	}

	@Override
	public List<Object> findByCondition(PlatMcInfoModel model, Pager p) {
		// TODO Auto-generated method stub
		return platMcInfoDao.findByCondition(model, p);
	}

	@Override
	public PlatMcInfo findById(String id) {
		// TODO Auto-generated method stub
		return platMcInfoDao.findById(id);
	}

	@Override
	public void save(PlatMcInfo instance) {
		// TODO Auto-generated method stub
		PlatMcInfo pmi = platMcInfoDao.findByMcId(instance.getMcId());//根据信息机编号查询
		//如果信息机编号不存在，则为新增，否则，为更新
		if(pmi == null){
			pmi = instance;
		}else{
			instance.setTheId(pmi.getTheId());
			instance.setUpdateTime(new Date());
		}
		platMcInfoDao.save(instance);
	}

	
	public void update(PlatMcInfo instance) {
		// TODO Auto-generated method stub
		platMcInfoDao.update(instance);
	}
	
	@Override
	public PlatMcInfo findByMcId(String mcId){
		return platMcInfoDao.findByMcId(mcId);
	}

}
